import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/utils/log.dart';

import 'package:ichinesereader/exam/ExamQuestionPage.dart';
import 'package:ichinesereader/exam/ExamTopicPage.dart';

import 'controllers/ExamPageController.dart';

///
// Part 试卷章节， 最高级别的 章节
///
class ExamSectionPage extends GetView<ExamPageController> {
  const ExamSectionPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(0),
      child: _buildExamSectionContent(),
    );
  }

  Widget _getDivider() {
    return Container(
        padding: const EdgeInsets.only(top: 10, bottom: 10),
        child: const Divider(
          height: 2,
          color: Colors.grey,
        ));
  }

  Widget _buildExamSectionContent() {
    //Section级别的 考题
    Log.debug('ExamSectionPage _buildExamSectionContent');
    Widget scrollView = Scrollbar(
        thumbVisibility: true,
        child: SingleChildScrollView(
          primary: true,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              GetX<ExamPageController>(
                init: controller,
                builder: (_) {
                  return _buildExamTopicPage();
                },
              ),
              _getDivider(),
              GetX<ExamPageController>(
                  init: controller,
                  builder: (_) {
                    return _buildExamQuestionPage();
                  }),
            ],
          ),
        ));

    return scrollView;
  }

  Widget _buildExamTopicPage() {
    Log.debug('ExamSectionPage _buildExamTopicPage');
    var examTopic = ExamTopicPage(
      questionStepTopic: controller.currentQuestionStepTopic.value,
    );
    return examTopic;
  }

  Widget _buildExamQuestionPage() {
    Log.debug('ExamSectionPage _buildExamQuestionPage');

    var examQuestion = ExamQuestionPage(
        questionStepBody: controller.currentQuestionStepBody.value);
    return examQuestion;
  }
}
